﻿using System;

namespace MapServer
{
    public class ProtocolPack
    {
        //用户登入
        public static byte[] UserLoginPack(string UserName, string PassWord)
        {
            char cCmd = '\x1';
            String sText = UserName + "\x0" + PassWord + "\x0";
            string strResult;
            char[] chBuf = new char[4];

            chBuf[0] = '\xfdfe';
            chBuf[1] = (char)(1 + sText.Length);
            chBuf[2] = (char)(chBuf[0] ^ chBuf[1]);
            chBuf[3] = cCmd;
            strResult = new string(chBuf);
            strResult += sText;

            return CPublic.FunStrToBytes(strResult);
        }
        //定位数据
        public static byte[] LocationPack( int iCheId )
        {
            char cCmd = '\x22';
            String sText =  CPublic.FunIntToStringEx(iCheId);
            string strResult;
            char[] chBuf = new char[4];

            chBuf[0] = '\xfdfe';
            chBuf[1] = (char)(1 + sText.Length);
            chBuf[2] = (char)(chBuf[0] ^ chBuf[1]);
            chBuf[3] = cCmd;
            strResult = new string(chBuf);
            strResult += sText;

            return CPublic.FunStrToBytes(strResult);
        }
        //最后一次定位数据
        public static byte[] LastLocationPack(int iCheId)
        {
            char cCmd = '\x49';
            String sText = CPublic.FunIntToStringEx(iCheId);
            string strResult;
            char[] chBuf = new char[4];

            chBuf[0] = '\xfdfe';
            chBuf[1] = (char)(1 + sText.Length);
            chBuf[2] = (char)(chBuf[0] ^ chBuf[1]);
            chBuf[3] = cCmd;
            strResult = new string(chBuf);
            strResult += sText;

            return CPublic.FunStrToBytes(strResult);
        }
        //下载围栏
        public static byte[] DownFencePack(int iCheId, String sFenceData)
        {
            char cCmd = '\x45';
            String sText = CPublic.FunIntToStringEx(iCheId);
            sText += sFenceData;
            string strResult;
            char[] chBuf = new char[4];

            chBuf[0] = '\xfdfe';
            chBuf[1] = (char)(1 + sText.Length);
            chBuf[2] = (char)(chBuf[0] ^ chBuf[1]);
            chBuf[3] = cCmd;
            strResult = new string(chBuf);
            strResult += sText;

            return CPublic.FunStrToBytes(strResult);
        }
        public static byte[] MileageStatistics(int iCheId, String sStarTime, String sEndTime)
        {
            char cCmd = '\x4d';
            String sText = CPublic.FunIntToStringEx(iCheId);
            sText += sStarTime;
            sText += "\x0";
            sText += sEndTime;
            sText += "\x0";
            string strResult;
            char[] chBuf = new char[4];

            chBuf[0] = '\xfdfe';
            chBuf[1] = (char)(1 + sText.Length);
            chBuf[2] = (char)(chBuf[0] ^ chBuf[1]);
            chBuf[3] = cCmd;
            strResult = new string(chBuf);
            strResult += sText;

            return CPublic.FunStrToBytes(strResult);
        }
    }
}
